package com.bi.onlineEducation.web.controller;

import com.bi.onlineEducation.annotation.WebProcess;
import com.bi.onlineEducation.domain.ExaminePo;
import com.bi.onlineEducation.service.ExamineService;
import com.bi.onlineEducation.utils.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: chenYuTao
 * @Time: 2022/5/15 21:17
 * @Description:
 **/
@Slf4j
@RestController
@Api(tags = "考试控制层", description = "考试数据接口")
public class ExamineController {

    @Resource
    private ExamineService examineService;

    @ApiOperation("查询所有")
    @WebProcess
    @GetMapping(value = "/examine/findAll")
    public ResultCode findAll() {
        return ResultCode.success(examineService.findAll());
    }

    @ApiOperation("根据id查询评论信息")
    @WebProcess
    @GetMapping(value = "/examine/findById")
    public ResultCode findById(@RequestParam("id") Integer id) {
        return ResultCode.success(examineService.findById(id));
    }

    @ApiOperation("查询所有没有绑定考试的课程")
    @WebProcess
    @GetMapping(value = "/examine/findAllByIsNotExistExamine")
    public ResultCode findAllByIsNotExistExamine() {
        return ResultCode.success(examineService.findAllByIsNotExistExamine());
    }

    @ApiOperation("根据cId查询课后题信息")
    @WebProcess
    @GetMapping(value = "/examine/findByCId")
    public ResultCode findByCId(@RequestParam("cId") Integer cId) {
        return ResultCode.success(examineService.findByCId(cId));
    }

    @ApiOperation("考试内容搜索所有")
    @WebProcess
    @GetMapping(value = "/examine/search")
    public ResultCode search(@RequestParam("title") String title) {
        return ResultCode.success(examineService.search(title));
    }

    @ApiOperation("保存信息")
    @WebProcess
    @PostMapping(value = "/examine/save")
    public ResultCode save(@RequestBody ExaminePo examinePo) {
        return ResultCode.success(examineService.save(examinePo));
    }

    @ApiOperation("修改信息")
    @WebProcess
    @PutMapping(value = "/examine/update")
    public ResultCode update(@RequestBody ExaminePo examinePo) {
        return ResultCode.success(examineService.save(examinePo));
    }

    @ApiOperation("课后题答案提交")
    @WebProcess
    @PutMapping(value = "/examine/updateSelected")
    public ResultCode updateSelected(@RequestBody ExaminePo examinePo) {
        return ResultCode.success(examineService.updateSelected(examinePo));
    }

    @ApiOperation("根据id删除评论信息")
    @WebProcess
    @DeleteMapping(value = "/examine/deleteById")
    public ResultCode deleteById(@RequestParam("id") Integer id) {
        return ResultCode.success(examineService.deleteById(id));
    }

    @ApiOperation("批量根据id删除考试信息")
    @WebProcess
    @DeleteMapping(value = "/examine/deleteByIds")
    public ResultCode deleteById(@RequestParam("ids") List<Integer> ids) {
        return ResultCode.success(examineService.deleteByIds(ids));
    }

}
